package com.jgsu.farm.mapper.sql;

import com.jgsu.farm.entity.StressCategory;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface StressCategoryMapperSql {
    @Select("select * from stresscategory where name = #{name} and mainType = #{maintype} and subType = #{subtype} and factor = #{factor}")
    Integer select(StressCategory stresscategory);

    @Insert("insert into stresscategory(name,mainType,subType,factor) values(#{name},#{maintype},#{subtype},#{factor})")
    @Options(useGeneratedKeys = true,keyProperty = "stressid",keyColumn = "stressID")
    void add(StressCategory stresscategory);

    @Select("select stressID from stresscategory where  name = #{name} and mainType = #{maintype} and subType = #{subtype} and factor = #{factor}")
    StressCategory selectId(StressCategory stresscategory);

    @Select("select stressID from stresscategory where  name = #{stressname}")
    Integer selectByName(String stressname);

    @Select("select stressID from stresscategory where stressID = #{stressid}")
    Integer selectById(Integer stressid);

    /**
     * 根据id查询是否存在该胁迫类型
     * */
    @Select("select stressID,name,mainType,subType,factor from stresscategory where stressID = #{stressid}")
    StressCategory selectStressCategoryById(Integer stressid);

    /**
     * 根据id删除胁迫类型
     * */
    @Delete("delete from stresscategory where stressID = #{stressid}")
    int deleteById(Integer stressid);
}
